<?php

namespace App\Http\Controllers\Admin;

use App\Http\Models\Paper;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class PaperController extends Controller
{
    //试卷列表显示
    public function index(Request $request){
        if($request->isMethod('post')){
            $cnt = Paper::count();
            //每页取出多少数据
            $start = $request->input('start');
            $len = $request->input('length');
            //排序字段的列数
            $column = $request->input('order.0.column');
            //排序的字段
            $field = $request->input('columns.'.$column.'.data');
            //排序的规则
            $order = $request->input('order.0.dir');
            $data = Paper::offset($start)
                ->limit($len)
                ->orderBy($field,$order)
                ->get();

            $info = [
                'draw'=>$request->input('draw'),
                'recordsTotal'=>$cnt,
                'recordsFiltered'=>$cnt,
                'data'=>$data
            ];
            return $info;
        }

        return view('admin.paper.index',compact('data'));
    }
}
